package com.lock;

import org.junit.Test;

import java.util.Random;

/**
 * @author: csh
 * @Date: 2021/12/19 15:05
 * @Description:
 */
public class PassiveUse2 {

    @Test
    public void test1(){
      //  System.out.println(Person.NUM);
        System.out.println(Person.NUM1);
    }

    @Test
    public void test2(){
        //  System.out.println(Person.NUM);
        System.out.println(SerialA.ID);
    }

    @Test
    public void test3 (){
        try {
            ClassLoader.getSystemClassLoader().loadClass("com.lock.Person");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}

class Person{
    static {
        System.out.println("Person类的初始化");

    }
    public static final int NUM = 1; //在链接过程的准备环节就被赋值为1了。
    public static final int NUM1 = new Random().nextInt(10); //在链接过程的准备环节就被赋值为1了。
}

interface SerialA{
    public static final Thread t = new Thread(){
        {
            System.out.println("SerialA的初始化");
        }
    };
    int ID = 1;
    int ID1 = new Random().nextInt(10);//此时的赋值操作需要在<clinit()> 中运行
}